/**
 * 系统管理 用户管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/userInfo/userInfo' }">首页</el-breadcrumb-item>

      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="pageparm" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="pageparm.userMobile" placeholder="请输入关键字" @change="search"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table :data="userListData" v-loading="loading" element-loading-text="拼命加载中" stripe style="width: 100%"
      :header-cell-style="{ 'text-align': 'center' }" :cell-style="{ 'text-align': 'center' }">
      <el-table-column align="center" prop="nickname" label="昵称">
      </el-table-column>
      <el-table-column align="center" prop="showId" label="ID">
      </el-table-column>
      <el-table-column align="center" prop="avatar" label="头像">
        <template slot-scope="scope">
          <el-image :src="scope.row.avatar" style="width: 40px; heigth: 40px; border-radius: 20px">
            <div slot="error" class="image-slot">
              <i class="el-icon-picture-outline"></i>
            </div>
          </el-image>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="sex" label="性别">
        <template slot-scope="scope">
          <div>{{ scope.row.sex == 1 ? "男" : "女" }}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" prop="createTime" label="加入时间" width="200">
      </el-table-column>

      <el-table-column label="操作" min-width="300">
        <template slot-scope="scope">
          <el-button size="mini" @click="deleteUser(scope.row)">
            踢出</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
  </div>
</template>

<script>
import { userList, kick } from "@/api/user";
import Pagination from "../../components/Pagination";
export default {
  data() {
    return {
      userListData: [],
      //用户数据
      userData: [],
      // 分页参数
      pageparm: {
        current: 1,
        size: 10,
        total: 10,
        keywords: "",
      },
    };
  },
  // 注册组件
  components: {
    Pagination,
  },

  /**
   * 数据发生改变
   */
  watch: {},

  /**
   * 创建完毕
   */
  created() {
    this.getdata();
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    deleteUser(row) {
      console.log(row);
      this.$confirm("您确定要踢出此人吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          kick({ userId: row.userId }).then((res) => {
            if (res.code == "200") {
              this.$message({
                type: "success",
                message: "踢出成功!",
              });
            } else {
              this.$message.info(res.msg);
            }
          });
          this.getdata();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 获取数据方法
    getdata() {
      this.loading = true;
      userList(this.pageparm).then((res) => {
        if (res.code == "200") {
          this.userListData = res.data.data;
          this.pageparm.total = Number(res.data.total);
          this.loading = false;
        } else {
          this.$message.info(res.msg);
        }
      });
    },
    // 分页插件事件
    callFather(parm) {
      this.pageparm.current = parm.currentPage || 1;
      this.pageparm.size = parm.pageSize || 10;
      this.getdata();
    },
    //搜索事件
    search() {
      this.getdata();
    },
    selectChange(e) {
      console.log('输出一下', e)
    }
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}

.userRole {
  width: 100%;
}
</style>

 